#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char **create_command_array(char* cmd)
{
    char **args = malloc(10 * sizeof(char *));
    char *token = strtok(cmd, " ");
    int i = 0;
    while (token != NULL && i < 10)
    {
        args[i++] = token;
        token = strtok(NULL, " ");
    }
    args[i] = NULL;
    return args;
}

/**
 * 函数返回指针的指针
*/
int main(int argc, char const *argv[])
{
    char cmd[] = "gcc -O2 -o test test.c";
    char **args = create_command_array(cmd);
    int i = 0;
    char **p;
    p = args;
    while (*(p+i) != NULL)
    {
        printf("%s\n", *(p+i));
        i++;
    }

    // while (args[i]!=NULL)
    // {
    //     printf("%s\n", args[i]);
    //     i++;
    // }

    return 0;
}